#!/usr/bin/env python
# -*- coding:utf-8 -*-
"""
@Author   : long.hai
@Contact  : 1982964634@qq.com
"""
import asyncio
from _base.base import BasePage


class Config(object):

    def __init__(self, base_page: BasePage):
        self.base_page = base_page

    def is_enable(self, enable):
        return True if enable == 1 else False

    def ignore_error(self, enable):
        return True if enable == 0 else False

    async def before_wait(self, wait_time):
        if isinstance(wait_time, str):
            wait_time = eval(wait_time)
        if wait_time > 0:
            await asyncio.sleep(wait_time)

    async def intelligence_wait(self, enable):
        # 判断是否开启智能等待页面加载稳定后执行
        if enable == 0:
            await self.base_page.intelligent_wait("load")

    async def after_screenshot(self, enable):
        if enable == 0:
            await self.base_page.screenshot()
